package com.yushutao.menu.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.yushutao.menu.beans.OrderBean;
import com.yushutao.menu.dao.IOrder;
import com.yushutao.menu.dao.MyBatisUtil;

public class OrderDAO implements IOrder{

	@Override
	public List<OrderBean> getOrderByUserId(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			return mapper.getOrderByUserId(id);
		}
	}

	@Override
	public List<OrderBean> getAllNeedCookie() {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			return mapper.getAllNeedCookie();
		}
	}

	@Override
	public void addOrder(OrderBean order) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			mapper.addOrder(order);
			session.commit();
		}
	}

	@Override
	public void removeOrder(int orderId,int userId) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			mapper.removeOrder(orderId, userId);
			session.commit();
		}
	}

	@Override
	public void removeAllOrderByUserId(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			mapper.removeAllOrderByUserId(id);
			session.commit();
		}
	}

	@Override
	public void confirmOrderByUserId(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			mapper.confirmOrderByUserId(id);
			session.commit();
		}
	}

	@Override
	public void finishCook(int id) {
		try(SqlSession session = MyBatisUtil.getSqlSessionFactory().openSession()){
			IOrder mapper = session.getMapper(IOrder.class);
			mapper.finishCook(id);
			session.commit();
		}
	}

}
